package hk.m4s.lr.repair.test.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.MyWaiteOrderModel;
import hk.m4s.lr.repair.test.ui.goods.GoodsEventActivity;
import hk.m4s.lr.repair.test.ui.user.MyoderEnValueActivity;
import hk.m4s.lr.repair.test.ui.user.OrderEnActivity;
import hk.m4s.lr.repair.test.views.listview.InnerListView;


/**
 * @author
 */
public class ItemEnValueOderAdapter extends BaseAdapter {
    private MyoderEnValueActivity context;
    public List<MyWaiteOrderModel> items;
    int selectNums=0;
    public ItemEnValueOderAdapter(MyoderEnValueActivity context,
                                  List<MyWaiteOrderModel> items) {
        this.context = context;
        this.items = items;
    }

    public int getCount() {
        return 2;
    }

    public Object getItem(int position) {
        return getView(position, null, null);
    }

    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_my_en_goods, null);
            holder = new ViewHolder();
            holder.order_shop_state = (TextView) convertView.findViewById(R.id.order_shop_state);
            holder.order_shop_name = (TextView) convertView.findViewById(R.id.order_shop_name);
            holder.order_shop_price = (TextView) convertView.findViewById(R.id.order_shop_price);
            holder.order_shop_size = (TextView) convertView.findViewById(R.id.order_shop_size);
            holder.order_shop_num = (TextView) convertView.findViewById(R.id.order_shop_num);
            holder.order_shop_fan = (TextView) convertView.findViewById(R.id.order_shop_fan);
           // holder.order_shop_buynum = (TextView) convertView.findViewById(R.id.order_shop_buynum);
            holder.order_shop_img = (ImageView) convertView.findViewById(R.id.order_shop_img);
            holder.enBtn= (Button) convertView.findViewById(R.id.enBtn);
            holder.butbtn= (Button) convertView.findViewById(R.id.butbtn);
            holder.goEvent= (LinearLayout) convertView.findViewById(R.id.goEvent);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.goEvent.setTag(position);
        holder.enBtn.setTag(position);
        holder.butbtn.setTag(position);
//        MyWaiteOrderModel model = items.get(position);
//        holder.order_shop_name.setText(model.getName());
//       // holder.order_shop_price.setText(MoneyTool.getLocalMoney(model.getPrice()));
//        holder.order_shop_size.setText(model.getSize());
//        holder.order_shop_num.setText("x" + model.getBuyNum());
//        if(model.getEvaluate()==0){
//            holder.enBtn.setVisibility(View.VISIBLE);
//            holder.enBtn.setBackgroundResource(R.drawable.btn_red_backroud);
//            holder.enBtn.setTextColor(Color.parseColor("#ff3b30"));
//            holder.enBtn.setText("我要评价");
//        }else{
//            holder.enBtn.setVisibility(View.GONE);
//            holder.enBtn.setBackgroundResource(R.drawable.btn_red_backroud);
//            holder.enBtn.setTextColor(Color.parseColor("#ff3b30"));
//            holder.enBtn.setText("查看评价");
//        }
//        try {
//            Glide.with(context).load(model.getImg()).asBitmap().placeholder(R.mipmap.device_list_no_img).error(R.mipmap.device_list_no_img).into(holder.order_shop_img);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        holder.goEvent.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                int num = (Integer) v.getTag();
//                MyWaiteOrderModel model = items.get(num);
//                Intent aboutIntent = new Intent(context, GoodsEventActivity.class);
//                aboutIntent.putExtra("goods_id",model.getGoods_id());
//                aboutIntent.putExtra("ids",model.getId());
//                context.startActivity(aboutIntent);
//            }
//        });
        holder.enBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
                //MyWaiteOrderModel model = items.get(num);
                //if(model.getEvaluate()==0) {
                    Intent aboutIntent = new Intent(context, OrderEnActivity.class);
//                    aboutIntent.putExtra("img", model.getImg());
//                    aboutIntent.putExtra("goodsName", model.getName());
//                    aboutIntent.putExtra("goodsId", model.getGoods_id());
//                    aboutIntent.putExtra("orderId",model.getOrderId());
//                    aboutIntent.putExtra("ids",model.getId());
//
//                    aboutIntent.putExtra("type","6");
//                    aboutIntent.putExtra("orderSize",model.getSize());
//                    aboutIntent.putExtra("orderId",model.getOrderId());
                    context.startActivity(aboutIntent);
                //}
            }
        });
//        holder.butbtn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                int num = (Integer) v.getTag();
//                MyWaiteOrderModel model = items.get(num);
////                    Intent aboutIntent = new Intent(context, OderTuiActivity.class);
////                    aboutIntent.putExtra("img", model.getImg());
////                    aboutIntent.putExtra("goodsName", model.getName());
////                    aboutIntent.putExtra("goodsId", model.getGoods_id());
////                    aboutIntent.putExtra("orderId",model.getOrderId());
////                    aboutIntent.putExtra("goodsDetails", model.getDetails());
////                    aboutIntent.putExtra("type","6");
////                    aboutIntent.putExtra("orderSize",model.getSize());
////                    context.startActivity(aboutIntent);
//            }
//        });
        return convertView;
    }

    private class ViewHolder {
        TextView order_shop_time;
        TextView order_shop_state;
        TextView order_shop_name;
        TextView order_shop_price;
        TextView order_shop_size;
        TextView order_shop_num;
        TextView order_shop_fan;
        TextView order_shop_buynum;
        TextView order_shop_totlaprice;
        ImageView order_shop_img;
        Button enBtn,butbtn;
        private RelativeLayout header;
        LinearLayout goEvent;
        InnerListView itemList;
    }

}
